package com.dep.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.SecurityScheme;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

import java.util.ArrayList;
import java.util.List;

@Configuration
@EnableSwagger2WebMvc
public class Swagger2 {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("APP")
                .apiInfo(apiAdminInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.dep.controller"))
                .paths(PathSelectors.any())
                .build()
                .securitySchemes(securitySchemesAdmin());
    }



    private ApiInfo apiAdminInfo() {
        return new ApiInfoBuilder().title("APP业务接口").description("测试使用").termsOfServiceUrl("外网访问:https://huanglt.goho.co/doc.html")
                .version("1.0")
                .build();
    }

    private List<SecurityScheme> securitySchemesAdmin() {
        ArrayList<SecurityScheme> list = new ArrayList<>();
        list.add(new ApiKey("token", "token", "header"));
        list.add(new ApiKey("sign", "sign", "header"));
        return list;
    }

}
